import { uDb, obj_str, cline, reload_col, loc } from 'sui';

const fix_col = () => {
    return [
        {sn: "sn", name: loc("l_488"), tp: "string"},
    ];
};

const load_col = (mod, setCol) => {
    const fix = fix_col();
    reload_col(null, v => setCol(v), mod, fix);
};

const get_mod = (cur) => {
    const mt = obj_str(cur, "mt");
    if (mt === "T") {
        return "cera";
    } else if (mt === "G") {
        return "stell";
    }

    return "";
};

const load_stock = (hDone, cur, setMain) => {
    const mt = get_mod(cur);
    if (!mt) {
        setMain(null);
        return;
    }

    uDb(hDone, `${mt}/get`,
        {
            line: cline(),
            k: obj_str(cur, "bsn"),
        },
        r => setMain(r), e => setMain(null));
};

export {get_mod, load_stock, load_col, fix_col};
